<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="音乐标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入音乐标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="歌手" prop="singer">
        <el-input
          v-model="queryParams.singer"
          placeholder="请输入歌手"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
            <el-form-item label="音乐类型" prop="typeData">
        <el-select v-model="queryParams.typeData" placeholder="请选择音乐类型">
            <el-option v-for="item in tvDataOptions" :key="item.id" :label="item.name" :value="item.id" :disabled="item.status == 1"></el-option>
            </el-select>
      </el-form-item>
      <el-form-item label="专辑名称" prop="albumTitle">
        <el-input
          v-model="queryParams.albumTitle"
          placeholder="请输入专辑名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
                  <el-form-item label="数据来源" prop="souceType">
        <el-select v-model="queryParams.souceType" placeholder="请选择数据来源">
            <el-option
            v-for="dict in dict.type.sys_movie_music_source_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
            </el-select>
      </el-form-item>
            <el-form-item label="创建时间">
                <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
              </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:musicData:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:musicData:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:musicData:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Download"
          size="mini"
          @click="downTemplate"
          v-hasPermi="['system:sysMovie:remove']"
        >下载模板</el-button>
      </el-col> 
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:musicData:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="musicDataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="音乐标题" align="center" prop="title" />
      <el-table-column label="歌手" align="center" prop="singer" />
      <el-table-column label="音乐类型" align="center" prop="musicType" />      
      <!-- <el-table-column label="专辑编号" align="center" prop="albumId" /> -->
      <!-- <el-table-column label="歌曲地址" align="center" prop="videoAddress" /> -->
      <!-- <el-table-column label="歌词地址" align="center" prop="lyricAddress" /> -->
      <!-- <el-table-column label="关键字搜索" align="center" prop="keyWord" /> -->
      <el-table-column label="专辑名称" align="center" prop="contentTitle" />
      <el-table-column label="专辑封面" align="center" prop="musicUrl" >
                  <template slot-scope="scope">
          <img v-bind:src="scope.row.imgUrl" class="img-lg" style="width: 80px;height: 50px;"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="歌词路径" align="center" prop="lyricUrl" /> -->
      <!-- <el-table-column label="专辑名称" align="center" prop="albumTitle" /> -->
      <!-- <el-table-column label="封面地址" align="center" prop="imgAddress" /> -->
      <!-- <el-table-column label="封面路径" align="center" prop="imgUrl" /> -->
      <!-- <el-table-column label="歌词" align="center" prop="songWord" /> -->
      <el-table-column label="数据来源" align="center" prop="souceType" >
       <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_movie_music_source_type" :value="scope.row.souceType"/>
        </template>
      </el-table-column>
       <el-table-column label="创建时间" align="center" prop="createTime" width="160">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
              </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['system:songData:query']"
          >详细</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:musicData:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改纯音乐享对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
            <el-row>
          <el-col :span="12">
        <el-form-item label="歌曲名称" prop="title">{{ form.title }}
        </el-form-item>
        </el-col>
      <el-col :span="12">
        <el-form-item label="歌手" prop="singer">{{ form.singer }}
        </el-form-item>
        </el-col>

      <el-col :span="12">
        <el-form-item label="音乐类型" prop="typeData">{{ form.musicType }}
        </el-form-item>
        </el-col>
      <el-col :span="12">
        <el-form-item label="专辑名称" prop="contentTitle">{{ form.contentTitle }}
        </el-form-item>
        </el-col>
       <el-col :span="12">
        <el-form-item label="数据来源" prop="souceType">
          <div v-if="form.souceType == 0 ">本地录入</div>
          <div v-else-if="form.souceType === 1 ">资源盘录入</div>
          <div v-else-if="form.souceType === 2 ">U盘挂载导入</div>
          <div v-else-if="form.souceType === 3 ">远程内容同步</div>
        </el-form-item>
        </el-col>
        <el-col :span="24">
        <el-form-item label="专辑封面路径" prop="description">{{ form.imgAddress }}
        </el-form-item>
        </el-col>
      <el-col :span="24">
        <el-form-item label="歌曲地址" prop="videoFile">{{ form.videoAddress }}
        </el-form-item>
      </el-col>
            <el-col :span="24">
        <el-form-item label="歌曲在线路径" prop="videoFile">{{ form.musicUrl }}
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="歌词地址" prop="songWord">{{ form.lyricAddress }}
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="歌词在线地址" prop="imgAddress">{{ form.lyricUrl }}
        </el-form-item>
      </el-col>
      <el-col :span="24">
        <el-form-item label="专辑图片地址" prop="recommendBanner">{{ form.imgAddress }}
        </el-form-item>
      </el-col>
     <el-col :span="24">
        <el-form-item label="专辑图片在线地址" prop="description">{{ form.imgUrl }}
        </el-form-item>
        </el-col> 
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMusicData, getMusicData, delMusicData, addMusicData, updateMusicData } from "@/api/system/musicData";
import { checkUsb,getFileData,getFileDataByPath,getContentType,getContentTypeData } from '@/api/index';

export default {
  name: "MusicData",
  dicts: ['sys_movie_music_source_type', 'sys_common_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 纯音乐享表格数据
      musicDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
            // 日期范围
            dateRange: [],      
      openDetail: false,
            tvDataOptions: [],      
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null,
        singer: null,
        albumId: null,
        fileType: 2,//音乐类型
        videoAddress: null,
        lyricAddress: null,
        keyWord: null,
        contentTitle: null,
        musicUrl: null,
        lyricUrl: null,
        imgAddress: null,
        imgUrl: null,
        songWord: null,
        souceType: null,
        albumTitle: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
        this.getContentTypeData({
          "typeId": this.queryParams.fileType,
         });
  },
  methods: {
    /** 查询纯音乐享列表 */
    getList() {
      this.loading = true;
              listMusicData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
      // listMusicData(this.queryParams).then(response => {
        this.musicDataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        fileType: null,
        singer: null,
        albumId: null,
        videoAddress: null,
        lyricAddress: null,
        keyWord: null,
        contentTitle: null,
        musicUrl: null,
        lyricUrl: null,
        createTime: null,
        imgAddress: null,
        imgUrl: null,
        songWord: null,
        souceType: null,
        albumTitle: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加纯音乐享";
    },
        handleView(row) {
      this.open = true;
      this.form = row;
    },
        getContentTypeData(data){
      getContentTypeData(data).then(response =>{
        this.tvDataOptions = response.data;
        }).catch(error => {
          console.log("获取内容分类的类型详情响应:"+error);
          return
        });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMusicData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改纯音乐享";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMusicData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMusicData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除纯音乐享编号为"' + ids + '"的数据项？').then(function() {
        return delMusicData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/musicData/export', {
        ...this.queryParams
      }, `musicData_${new Date().getTime()}.xlsx`)
    },
            downTemplate(){
      this.download('system/musicData/importTemplate', {
      }, `电影模板_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
